home *** CD-ROM | disk | FTP | other *** search
/ Super Shareware Collection / Super Shareware Collection.iso / os_2 / mwave2.zip / MWAVE.PAS < prev    next >
Pascal/Delphi Source File  |  1994-02-06  |  6KB  |  186 lines

  1. program makewave;
  2.  
  3. {
  4.  ***************************************************************************
  5.  *                                                                         *
  6.  *            Wave maker for SoundBlaster 1.5 by HaJott                    *
  7.  *                                                                         *
  8.  ***************************************************************************
  9.    Discription of data types :
  10.  
  11.    type
  12.       chunk = record
  13.         main               : string[4];             = RIFF
  14.         main_length        : array[0..3] of byte;   = length of file
  15.         chunk_type         : string[4];             = WAVE
  16.         sub_chunk          : string[4];             = fmt_ :_=space=ASCII 32
  17.         sub_chunk_length   : array[0..3] of byte;   = always 16 bytes
  18.                                                       don't know why !
  19.         format             : word;                  = always 1 for PCM mode
  20.                              every SoundBlaster works with format = 1
  21.         modus              : word;                  1 = mono, 2 = stereo
  22.         sample_freq        : array[0..3] of byte;   11.025 kHz = $2B11
  23.                                                     22.050 kHz = $5622
  24.                                                     44.100 kHz = $AC44
  25.         bytes_per_sec      : array[0..3] of byte;   as it is
  26.         bytes_per_sample   : word;                  1 = 8 Bit, 2 = 16 Bit
  27.         bits_per_sample    : word;                  only 8, 12 or 16
  28.         data_chunk         : string[4];             = data
  29.         data_length        : array[0..3] of byte;   length of data block
  30.       end;
  31.  
  32. }
  33.  
  34. {$N+}
  35.  
  36.  type
  37.         w                  = word;
  38.         dw                 = array[0..3] of byte;
  39. {       w                  = array[0..1] of byte;}
  40. {       st                 = string[4]; }
  41.         dat                = array[1..16384] of byte;
  42.  
  43.       recordType = record
  44.         main               : dw{st} ;
  45.         main_length        : dw;
  46.         chunk_type         : dw{st};
  47.         sub_chunk          : dw{st};
  48.         sub_chunk_length   : dw;
  49.         format             : w;
  50.         modus              : w;
  51.         sample_freq        : dw;
  52.         bytes_per_sec      : dw;
  53.         bytes_per_sample   : w;
  54.         bits_per_sample    : w;
  55.         data_chunk         : dw{st};
  56.         data_length        : dw;
  57.         rf                 : dat;
  58.       end;
  59.     datafile = recordType;
  60.  
  61. var i,j,k,maxdat:integer;
  62.     datei1:file of datafile;
  63.     ri : byte;
  64.     x:extended;
  65.     stepx : real;
  66.     code:word;
  67.     p:pointer;
  68.     lenght : integer;
  69.     chunk                :  recordType;
  70.     step                 :  Integer;
  71.     bol                  :  Boolean;
  72.     wo                   :  word;
  73.     sinortri             :  char;
  74.  
  75.  
  76.  
  77. procedure initall;
  78. begin
  79.   x:=0; code:=0;i:=0;k:=0;j:=0;bol:=true;
  80.   chunk.main[0]:=ord('R');
  81.   chunk.main[1]:=ord('I');
  82.   chunk.main[2]:=ord('F');
  83.   chunk.main[3]:=ord('F');
  84.   chunk.main_length[0]:=45;
  85.   chunk.main_length[1]:=64;
  86.   chunk.main_length[2]:=0;
  87.   chunk.main_length[3]:=0;
  88.   chunk.chunk_type[0]:=ord('W');
  89.   chunk.chunk_type[1]:=ord('A');
  90.   chunk.chunk_type[2]:=ord('V');
  91.   chunk.chunk_type[3]:=ord('E');
  92.   chunk.sub_chunk[0]:=ord('f');
  93.   chunk.sub_chunk[1]:=ord('m');
  94.   chunk.sub_chunk[2]:=ord('t');
  95.   chunk.sub_chunk[3]:=ord(' ');
  96.   chunk.sub_chunk_length[0]:=16;
  97.   chunk.sub_chunk_length[1]:=0;
  98.   chunk.sub_chunk_length[2]:=0;
  99.   chunk.sub_chunk_length[3]:=0;
  100.   chunk.format:=1;
  101.   chunk.modus:=1;
  102.   chunk.sample_freq[0]:=17;
  103.   chunk.sample_freq[1]:=43;
  104.   chunk.sample_freq[2]:=0;
  105.   chunk.sample_freq[3]:=0;
  106.   chunk.bytes_per_sec[0]:=68;
  107.   chunk.bytes_per_sec[1]:=172;
  108.   chunk.bytes_per_sec[2]:=0;
  109.   chunk.bytes_per_sec[3]:=0;
  110.   chunk.bytes_per_sample:=4;
  111.   chunk.bits_per_sample:=8;
  112.   chunk.data_chunk[0]:=ord('d');
  113.   chunk.data_chunk[1]:=ord('a');
  114.   chunk.data_chunk[2]:=ord('t');
  115.   chunk.data_chunk[3]:=ord('a');
  116.   chunk.data_length[0]:=0;
  117.   chunk.data_length[1]:=40;
  118.   chunk.data_length[2]:=0;
  119.   chunk.data_length[3]:=0;
  120. for j:=1 to 16384 do chunk.rf[i]:=0;
  121. end;
  122.  
  123. begin
  124. initall;
  125. writeln;
  126. writeln (' Wave maker for SoundBlaster 1.5 by HaJott ');
  127. writeln;
  128. writeln (' Enter number in () to create wave ');
  129. write ('Pulse wave (2), Sinus wave (1), triangle wave (0) : ');
  130. readln(sinortri);
  131. case sinortri of
  132. ('1') :
  133.       begin
  134.            stepx:=0.4;
  135.                {*** stepx makes the frequency, 0.4=low 0.8=high ***}
  136.            writeln;
  137.            writeln ('Make Sinus ');
  138.            for i:=1 to 16384 do
  139.              begin
  140.               chunk.rf[i]:=abs(round(127+127*sin(x)));
  141.               {this makes a sinus wave between 0 and 254 (8bit)}
  142.               x:=x+stepx;
  143.              end; {for i:=1 to 16384 do}
  144.       end;
  145. ('2') :
  146.       begin
  147.            i:=0;
  148.            step:=16;
  149.             {*** step makes the frequency, step=64 means low step=16 high}
  150.            maxdat:=16384 div (2*step);
  151.            writeln;
  152.            writeln ('Make Pulse ');
  153.            for k:=1 to maxdat do
  154.             begin
  155.              for j:=1 to step do begin inc(i); chunk.rf[i]:=0;end;
  156.              for j:=1 to step do begin inc(i); chunk.rf[i]:=255;end;
  157.              {*** makes a pulse wave between 0 and 255 (8bit) ***}
  158.             end; {for k:=1 to 256 do}
  159.        end
  160. else
  161.        begin {makes a triangle wave between 0 an 254 (8bit)}
  162.          writeln;
  163.          writeln ('Make Triangle ');
  164.          step:=8; {step makes the frequency, step=8 means low step=16 high}
  165.          while (i<=16384) do
  166.            begin
  167.              if chunk.rf[i]>=(255-step) then begin step:=-step;bol:=false;end;
  168.              if chunk.rf[i]<=(step) then begin step:=abs(step);bol:=true;end;
  169.              inc(i);
  170.              chunk.rf[i]:=chunk.rf[i-1]+step;
  171.            end;
  172.        end;
  173. end;{case}
  174.  
  175. writeln ('Size of complete Datafile : ',SizeOf(chunk));
  176. writeln ('Size of wave data : ',SizeOf(chunk.rf));
  177.   chunk.main_length[0]:=lo(SizeOf(chunk));
  178.   chunk.main_length[1]:=hi(SizeOf(chunk));
  179.   chunk.data_length[0]:=lo(SizeOf(chunk.rf));
  180.   chunk.data_length[1]:=hi(SizeOf(chunk.rf));
  181. assign(datei1,'c:\mmos2\sounds\aaa.wav');
  182. rewrite(datei1);
  183. write (datei1,datafile(chunk));
  184. close(datei1);
  185. end.
  186.